package com.ansion.baseui.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import androidx.annotation.NonNull;

/**
 * created by zhaoyuntao
 * on 02/09/2021
 * description:
 */
public abstract class TVPBaseUIProxy<V extends TVPBaseView<?, ?>, P extends TBasePresenter<?>> {
    private final V v;

    public TVPBaseUIProxy(V v) {
        this.v = v;
    }

    @SuppressWarnings("unchecked")
    @NonNull
    final public P getPresenter() {
        P p = (P) v.getPresenter();
        if (p == null) {
            throw new RuntimeException("Please don't use this method in initView()!");
        }
        return p;
    }

    public abstract Activity activity();

    final public Intent getIntent() {
        return activity().getIntent();
    }

    protected abstract void initView(Bundle savedInstanceState);

    protected abstract void initData(Bundle savedInstanceState);

    @NonNull
    final public V getView() {
        return v;
    }

    /**
     * @return true means consume this click
     */
    protected boolean onClickView(View v) {
        return false;
    }

    /**
     * @return true means consume this click
     */
    protected boolean onPressedBack() {
        return false;
    }

    protected boolean onKeyPressedDown(int keyCode, KeyEvent event) {
        return false;
    }
}
